package com.parttimetask.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.parttimetask.R;
import com.parttimetask.bean.HomeListBean;
import com.parttimetask.databinding.ItemBinding;

import java.util.List;
public class HomeListAdapter extends ArrayAdapter<HomeListBean> {
    private static final int layoutId = R.layout.item;
    private final Activity context;
    public HomeListAdapter(Activity context, List<HomeListBean> objects ){
        super(context,layoutId,objects);
        this.context=context;
    }
    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        HomeListBean bean = getItem(position);
        @SuppressLint("ViewHolder") @NonNull ItemBinding binding = ItemBinding.inflate(LayoutInflater.from(context));
        Glide.with(context).setDefaultRequestOptions(new RequestOptions().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE)).load(bean.img).into(binding.itemIcon);
        binding.itemApply.setOnClickListener(view -> context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(bean.link))));
        binding.itemJobType.setText(bean.JobType);
        binding.itemLook.setText(bean.look);
        binding.itemSalary.setText(bean.salary);
        binding.itemTitle.setText(bean.title);
        binding.itemPayType.setText(bean.payType);
        return binding.getRoot();
    }
}